<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <title>属性查看</title>
    <link href="/static/css/open.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="../static/js/include.js?jquery,validation,dvs"></script>
    <script src="../static/js/jquery/jquery-1.12.1.min.js" type="text/javascript"></script>
    <script src="../static/js/validation/jquery.validate.js" type="text/javascript"></script>
    <script src="../static/js/validation/additional-methods.min.js" type="text/javascript"></script>
    <script src="../static/js/validation/localization/messages_zh.js" type="text/javascript"></script>
    <link href="../static/js/validation/jquery.validate.custom.css" rel="stylesheet" type="text/css">
    <script src="../static/js/validation/jquery.validate.custom.js" type="text/javascript"></script>
    <link href="../static/js/qtip/jquery.qtip.min.css" rel="stylesheet" type="text/css">
    <script src="../static/js/qtip/jquery.qtip.min.js" type="text/javascript"></script>
    <script src="../static/js/dvs.js" type="text/javascript"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <script type="text/javascript">
        var STR_ADD = "添加";
        var STR_DEL = "删除";
        var OPTION_MIN = 1;
        var OPTION_MAX = 7;
        var upGradeCharInfoMaps = []
        var temSelectObj = {};
        var temInputObj = {};
        var num = 0;
        var itseq;
        var type = 1;
        var delFlag = false;

        function onError() {
            // alert("非法操作!");
            // setTimeout("window.opener=null;window.open('', '_self');window.close();", 0 );
        }

        function CloseWin() {
            setTimeout("window.opener=null;window.open('', '_self');window.close();", 0);
        }

        function onOptionChange(ckObject, i) {

            if (ckObject.checked) {
                for (var k = 1; k <= num; k++) {
                    document.getElementById("OptionList" + k).value = temSelectObj['IT_OPTIONID' + k];
                    document.getElementById("Value" + k).value = temInputObj['IT_OPTIONVALUE' + k];
                }
                if (Number(document.getElementById('OptionList' + i).value) > 0) {
                    document.getElementById('OptionList' + i).value = 0;
                    document.getElementById("Value" + i).value = 0;
                }
                for (var j = OPTION_MIN; j <= OPTION_MAX; j++) {
                    if (i != j) {
                        document.getElementById('Change' + j).disabled = true
                    }
                }
                document.getElementById('OptionList' + i).disabled = false
            } else {

                for (var k = 1; k <= num; k++) {
                    document.getElementById("OptionList" + k).value = temSelectObj['IT_OPTIONID' + k];
                    document.getElementById("Value" + k).value = temInputObj['IT_OPTIONVALUE' + k];
                }
                if (Number(document.getElementById('OptionList' + i).value)) {

                } else {

                    document.getElementById('OptionList' + i).value = 0
                    document.getElementById('Value' + i).value = 0
                    let pDom = document.getElementById("actiontype" + i);
                    pDom.removeChild(pDom.firstElementChild);
                    var htm = '<font color="#7fff00"">添加</font>'
                    pDom.innerHTML = htm;
                }
                for (var j = OPTION_MIN; j <= OPTION_MAX; j++) {
                    document.getElementById('Change' + j).disabled = false
                }
                document.getElementById('OptionList' + i).disabled = true
            }
        }

        function obtainItemName() {
            var slottype = $("#slottype").val();
            if (slottype == 4 || slottype == 5 || slottype == 6 || slottype == 7 || slottype == 8) {
                type = 2
            }
            num = 0;
            for (var j = OPTION_MIN; j <= OPTION_MAX; j++) {
                document.getElementById('Change' + j).checked = false;
                document.getElementById('Change' + j).disabled = false;
                document.getElementById('OptionList' + j).disabled = true;
                let pDom = document.getElementById("actiontype" + j);
                pDom.removeChild(pDom.firstElementChild);
                var htm = '<font color="#7fff00"">添加</font>'
                pDom.innerHTML = htm;

            }
            dvs.ajax({
                url: "/webUp/obtainUpGradeCharInfoMaps?type=" + type,
                loading: "modal",
                type: 'get',
                callback: function (json) {
                    if (json.code == 200) {
                        upGradeCharInfoMaps = json.data
                        for (var j = 1; j <= OPTION_MAX; j++) {
                            let htm = '<option value="0">无</option>'
                            for (var i = 0; i < upGradeCharInfoMaps.length; i++) {
                                htm += '<option value="' + (i + 1) + '">' + upGradeCharInfoMaps[i].WUC_NAME + '</option>'
                            }
                            document.getElementById('OptionList' + j).innerHTML = htm;
                        }
                        var slottype = $("#slottype").val();
                        dvs.ajax({
                            url: "/webUp/obtainItemName",
                            loading: "modal",
                            param: {
                                IT_SLOTTYPE: slottype
                            },
                            callback: function (json) {
                                if (json.code == 200) {
                                    itseq = json.data.IT_SEQ;
                                    document.getElementById('itemName').innerText = json.data.IC_ITEMNAME;
                                    var reg1 = new RegExp(/^IT_OPTIONID/)
                                    var reg2 = new RegExp(/^IT_OPTIONVALUE/)
                                    for (var re in json.data) {
                                        var ret1 = reg1.test(re);
                                        var ret2 = reg2.test(re);
                                        if (ret1) {
                                            num++;
                                            temSelectObj[re] = json.data[re];
                                        }
                                        if (ret2) {
                                            temInputObj[re] = json.data[re];
                                        }
                                    }

                                    for (var i = 1; i <= num; i++) {
                                        document.getElementById("OptionList" + i).value = temSelectObj['IT_OPTIONID' + i];
                                        if(slottype==3){
                                            document.getElementById("Value" + i).value = temInputObj['IT_OPTIONVALUE' + i] * 2;
                                        }else{
                                            document.getElementById("Value" + i).value = temInputObj['IT_OPTIONVALUE' + i];

                                        }

                                    }
                                    regSelectValue()
                                }
                            }
                        })
                    }
                }
            })

        }

        //	选择属性项时触发,禁止属性重复
        function onSelectChange(selObj, i) {
            let selectVal = nature(selObj.value);
            for (var j = OPTION_MIN; j <= OPTION_MAX; j++) {
                if (selObj.value != 0) {
                    if (document.getElementById("OptionList" + j).value == selObj.value && i != j) {
                        alert('属性重复!!!')
                        document.getElementById("OptionList" + i).value = 0
                        document.getElementById('Value' + i).value = '';
                        return
                    }
                }
            }
            if (selObj.value == 0) {
                document.getElementById('Value' + i).value = '';
            } else {
                let pDom = document.getElementById("actiontype" + i);
                pDom.removeChild(pDom.firstElementChild);
                // var htm = '<font color="#7fff00" onclick="delValue('+i+')">删除</font>'
                var htm = '<font color="#7fff00">删除</font>'
                pDom.innerHTML = htm;
                document.getElementById('Value' + i).value = selectVal;
            }
        }

        function CheckSubmin() {
            var flag = false;
            for (var j = OPTION_MIN; j <= OPTION_MAX; j++) {
                if (document.getElementById('Change' + j).checked) {
                    flag = true
                }
            }
            if (!flag) {
                alert("请选择操作的选项！！！")
                return
            }
            var obj = {"WUC_FREEVALUE": 0, "WUC_NAME": "无", "WUC_OPTIONVALUE": 0};
            upGradeCharInfoMaps.unshift(obj)
            var slottype = $("#slottype").val();
            for (var i = 1; i <= num; i++) {
                var x = document.getElementById("OptionList" + i).value;
                temSelectObj['IT_OPTIONID' + i] = document.getElementById("OptionList" + i).value;
                if (document.getElementById("Change" + i).checked == true && Number(document.getElementById('OptionList' + i).value) != 0) {
                    temInputObj['IT_OPTIONVALUE' + i] = (+(document.getElementById("Value" + i).value)) + (upGradeCharInfoMaps[x].WUC_FREEVALUE || 0);
                } else {
                    temInputObj['IT_OPTIONVALUE' + i] = (+(document.getElementById("Value" + i).value));
                }
            }
            let obj3 = {};
            for (var attr in temSelectObj) {
                obj3[attr] = temSelectObj[attr];
            }
            for (var attr in temInputObj) {
                obj3[attr] = temInputObj[attr];
            }
            obj3.IT_SEQ = itseq;
            obj3.CT_GOLD = 30000000;
            dvs.ajax({
                url: "/webUp/updateItemInfoByID",
                loading: "modal",
                param: obj3,
                callback: function (json) {
                    if (json.code == 200) {
                        alert(json.message)
                        obtainItemName()
                    } else {
                        dvs.alert(json.message);
                    }
                }
            })
            return;
            for (var i = OPTION_MIN; i <= OPTION_MAX; i++) {
                var obj = document.getElementById("Change" + i);
                if (obj == undefined) {
                    onError();
                    return;
                }
                if (obj.checked == true) {
                    //	取得要升级的属性ID值
                    aryItemOptionName = tmpOptionName.split(",");
                    var nUpdateIndex = i;
                    var opList = document.getElementById("OptionList" + nUpdateIndex);
                    if (aryItemOptionName[opList.value] == "无") {
                        alert("请选择要操作的属性项!");
                        return;
                    }

                    // if( document.getElementById("UsePoint").checked == true && Number(opList.value) == Number(main.OPTIONID_ALLSKILLUP) )
                    // {
                    //     alert("只使用积分不能升级所有技能提升属性!");
                    //     return;
                    // }


                    var UID = json.data.CT_USERID;
                    var ITEMSEQ = json.data.IT_ITEMIDX;
                    var OPINDEX = i;
                    var OPOLDID = opList.value;
                    var NEWID = opList.value;
                    var ADD = 0;
                    var PROTECT = 0;
                    var ONLYUSEPOINT = 0;
                    var MYPOINT = json.data.CT_POINT;
                    var MYINGOT = json.data.CT_INGOT;
                    var MYGOLD = json.data.CT_GOLD;
                    var NEED_GOLD = "50000000";
                    var NEED_GOLD_DEL = "10000000";
                    // if( document.getElementById("UsePoint").checked == true )
                    // {
                    //     ONLYUSEPOINT = 1;
                    // }
                    // else
                    // {
                    //     ONLYUSEPOINT = 0;
                    // }

                    if (document.getElementById("actiontype" + i).innerHTML == STR_DEL) {
                        ADD = 0;
                        // //	判断元宝,积分数量
                        // if( Number(MYPOINT) < (Number(main.NEED_POINT_DEL)) )
                        // {
                        //     alert("积分数量不足!需要"+ (Number(main.NEED_POINT_DEL)) + "积分才能删除一个属性");
                        //     return;
                        // }
                        // if( Number(main.MYINGOT) < Number(main.NEED_INGOT_DEL) )
                        // {
                        //     alert("元宝数量不足!需要"+ main.NEED_INGOT_DEL +"元宝才能删除一个属性.");
                        //     return;
                        // }
                        if (Number(MYGOLD) < Number(NEED_GOLD_DEL)) {
                            alert("金币数量不足,你需要" + NEED_GOLD + "金币才能添加一个属性.");
                            return;
                        }
                    } else if (document.getElementById("actiontype" + i).innerHTML == STR_ADD) {
                        ADD = 1;
                        // if( Number(main.MYPOINT) < Number(main.NEED_POINT) )
                        // {
                        //     alert("积分数量不足!需要"+ main.NEED_POINT + "积分才能添加一个属性");
                        //     return;
                        // }
                        // if( Number(main.MYINGOT) < Number(main.NEED_INGOT) && document.getElementById("UseIngot").checked == true )
                        // {
                        //     alert("元宝数量不足!需要"+ main.NEED_INGOT +"元宝才能添加一个属性.");
                        //     return;
                        // }
                        if (Number(MYGOLD) < Number(NEED_GOLD)) {
                            alert("金币数量不足,你需要" + NEED_GOLD + "金币才能添加一个属性.");
                            return;
                        }

                    }
                    debugger
                    var strParm = "USERID=" + UID + "&ITEMSEQ=" + ITEMSEQ + "&OPINDEX=" +
                        OPINDEX + "&OPOLDID=" + OPOLDID + "&OPNEWID=" + NEWID + "&ADD=" + ADD + "&PROTECT=" + PROTECT +
                        "&ONLYUSEPOINT=" + ONLYUSEPOINT + '&Cnt=' + new Date().getTime();
                    dvs.alert(strParm)
                    RequestUpdateItemResult("updaterequest.asp?" + strParm);
                    setTimeout("window.opener=null;window.open('', '_self');window.close();", 0);
                    return;
                }
            }
            alert("你还没选择需要操作哪个属性!");
            return;
        }

        function nature(i) {
            if (i == 0) return i
            return upGradeCharInfoMaps[i - 1].WUC_OPTIONVALUE
        }

        function regSelectValue() {
            for (var i = 1; i <= num; i++) {
                if (Number(document.getElementById('OptionList' + i).value) != 0) {
                    let pDom = document.getElementById("actiontype" + i);
                    pDom.removeChild(pDom.firstElementChild);
                    // var htm ='<font color="#7fff00" onclick="delValue('+i+')">删除</font>'
                    var htm = '<font color="#7fff00">删除</font>'
                    pDom.innerHTML = htm;
                }
            }
        }

        function delValue(i) {

            document.getElementById('OptionList' + i).value = 0;
            document.getElementById('Value' + i).value = 0;
            let pDom = document.getElementById("actiontype" + i);
            pDom.removeChild(pDom.firstElementChild);
            var htm = '<font color="#7fff00"">添加</font>'
            pDom.innerHTML = htm;
        }

        window.onload = function () {
            obtainItemName()
        }

    </script>
    <style type="text/css">
        Body {
            text-Align: Center;
            Font-Size: 9pt;
            color: #FFFFFF;
        }
    </style>
</head>

<body>
<div style="position: absolute; left: 0px; top: 0px; width:443px;height:508px;background-image:url(../static/image/optionbg.jpg);background-size: 100% 100%">
    <input type="hidden" th:value="${slottype}" id="slottype">
    <!--    <input type="hidden" th:value="${open}" id="open">-->
    <table align="center" cellspacing="0">
        <tbody>
        <tr>
            <td align="center" colspan="3">
                <font color="#7fff00" size="4">
                    <div id="sItemName">&nbsp;&nbsp;&nbsp;属性改造</div>
                </font>

            </td>
        </tr>

        <tr>
            <td>
                <select disabled id="OptionList1" onchange="onSelectChange(this,1);" size="1">

                </select>

            </td>
            <td><input id="Value1" readonly="readonly" type="text" size="4"></td>
            <td>
                <input id="Change1" onclick="onOptionChange(this,1);" type="checkbox" value=""><span
                    id="actiontype1"><font color="#7fff00">添加</font></span>
            </td>
        </tr>
        <tr>
            <td>
                <select disabled id="OptionList2" onchange="onSelectChange(this,2);" size="1">

                </select>
            </td>
            <td><input id="Value2" readonly="" type="text" size="4"></td>
            <td><input id="Change2" onclick="onOptionChange(this,2);" type="checkbox" value=""><span
                    id="actiontype2">
                            <font color="#7fff00">添加</font>
                        </span></td>
        </tr>
        <tr>
            <td>
                <select disabled id="OptionList3" onchange="onSelectChange(this,3);" size="1">

                </select>
            </td>
            <td><input id="Value3" readonly="" type="text" size="4"></td>
            <td><input id="Change3" onclick="onOptionChange(this,3);" type="checkbox" value=""><span
                    id="actiontype3">
                            <font color="#7fff00">添加</font>
                        </span></td>
        </tr>
        <tr>
            <td>
                <select disabled id="OptionList4" onchange="onSelectChange(this,4);" size="1">

                </select>
            </td>
            <td><input id="Value4" readonly="" type="text" size="4"></td>
            <td><input id="Change4" onclick="onOptionChange(this,4);" type="checkbox" value=""><span
                    id="actiontype4">
                            <font color="#7fff00">添加</font>
                        </span></td>
        </tr>
        <tr>
            <td>
                <select disabled id="OptionList5" onchange="onSelectChange(this,5);" size="1">

                </select>
            </td>
            <td><input id="Value5" readonly="" type="text" size="4"></td>
            <td><input id="Change5" onclick="onOptionChange(this,5);" type="checkbox" value=""><span
                    id="actiontype5">
                            <font color="#7fff00">添加</font>
                        </span></td>
        </tr>
        <tr>
            <td>
                <select disabled id="OptionList6" onchange="onSelectChange(this,6);" size="1">

                </select>
            </td>
            <td><input id="Value6" readonly="" type="text" size="4"></td>
            <td><input id="Change6" onclick="onOptionChange(this,6);" type="checkbox" value=""><span
                    id="actiontype6">
                            <font color="#7fff00">添加</font>
                        </span></td>
        </tr>
        <tr>
            <td>
                <select disabled id="OptionList7" onchange="onSelectChange(this,7);" size="1">

                </select>


            </td>
            <td><input id="Value7" readonly="" type="text" size="4"></td>
            <td><input id="Change7" onclick="onOptionChange(this,7);" type="checkbox" value=""><span
                    id="actiontype7">
                            <font color="#7fff00">添加</font>
                        </span></td>
        </tr>
        <tr>
            <td colspan="3" align="center">
                <font style="font-weight: bold" color="#adff2f" size="4">
                    <div id="itemName"></div>
                </font>
            </td>
        </tr>
        <tr>
            <td colspan="3" align="middle"><input name="btnUpdate" type="button" maxsize="10" onclick="CheckSubmin();"
                                                  value="提交">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="btnCancel"
                                                                                                  type="button"
                                                                                                  onclick="CloseWin();"
                                                                                                  value="取消">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
                    name="btnUpgradeChart" type="button" onclick="javascript:window.open('/optionvalue');"
                    value="查看升级属性表"></td>
        </tr>
        </tbody>
    </table>

</div>

</body>
<div style="pointer-events: none; visibility: hidden; position: absolute;"></div>
<div style="all: initial;">
    <div></div>
</div>

</html>